<?php

if(!empty($_POST)){

	include ("xlthemtinbai.php");

}else{

define("ROOT_PATH",str_replace("admin","",dirname($_SERVER['PHP_SELF'])));

//echo ROOT_PATH;

include('../fckeditor/fckeditor.php'); 



$sids = $_SESSION["ArraySec"];

 if($_SESSION['Permit']==1)

$sql = "select id,name from tblsection";

else

$sql = "select id,name from tblsection where id in ($sids)";

$rs = mysql_query($sql);

$slcSection = "<select id='slcSection' name='sid'><option value='0'>Chọn một section</option>";

while($row=mysql_fetch_array($rs)){

	$slcSection.="<option value='". $row["id"]."'>".$row["name"]."</option>";  

}
$sql2 = "select * from tblmenu";

$rs = mysql_query($sql2);

$slcmenu = "<select id='slcSection' name='slcmenu'><option value='0'>Chọn một Mục</option>";

while($row=mysql_fetch_array($rs)){

	if ($row["parent_id"]==0){
	$slcmenu.="<option value='". $row["id"]."'>".$row["vi_name"]."</option>";	
	$sql3 = "select * from tblmenu where parent_id=".$row["id"];
	$rs3 = mysql_query($sql3);
	while($row3=mysql_fetch_array($rs3)){
	$slcmenu.="<option value='". $row3["id"]."'>--".$row3["vi_name"]."</option>";	
	$sql4 = "select * from tblmenu where parent_id=".$row3["id"];
	$rs4 = mysql_query($sql4);
	while($row4=mysql_fetch_array($rs4)){
	$slcmenu.="<option value='". $row4["id"]."'>----".$row4["vi_name"]."</option>";	
	
	}
	}
	}

}
	
?>

<script type="text/javascript" src="<?php echo ROOT_PATH."ckfinder/ckfinder.js"?>">

</script>

<script language="javascript" type="text/javascript">



function addArticle(){

	var frm = document.frmAddArticle;

	var sid = document.getElementsByName("sid").item(0).value;

	var vi_title = frm.vi_title.value;

	var vi_summary = frm.vi_summary.value;

	var vi_content = frm.vi_content.value;

	var en_title = frm.en_title.value;

	var en_summary = frm.en_summary.value;

	var en_content = frm.en_content.value;

	

	var tag = frm.tag.value;

	

	var msg ="";

	if(sid == 0){

		msg+="Hãy chọn một chuyên mục cho bài viết!\n";

	}

	if(vi_title ==""){

		msg+="Thiếu tiêu đề Tiếng Việt!\n";

	}

	if(vi_summary == ""){

		msg+="Thiếu tóm tắt Tiếng Việt!\n";

	}

//	if(vi_content==""){

//		msg+="Thiếu nội dung Tiếng Việt!\n";

//	}



	if(en_title ==""){

		msg+="Thiếu tiêu đề Tiếng Anh !\n";

	}

	if(en_summary == ""){

		msg+="Thiếu tóm tắt Tiếng Anh!\n";

	}

//	if(en_content==""){

//		msg+="Thiếu nội dung Tiếng Anh!\n"

//	}

	

	if(tag==""){

		msg+="Thiếu từ khóa hỗ trợ tìm kiếm!\n"

	}

	

	if(msg.length==0){

		frm.submit();

	}else{

		alert(msg);

	}

}

function BrowseServer()

{

	// You can use the "CKFinder" class to render CKFinder in a page:

	var finder = new CKFinder() ;

	finder.basePath = '<?php echo str_replace("admin","",ROOT_PATH)."ckfinder/";?>' ;	// The path for the installation of CKFinder (default = "/ckfinder/").

	

	finder.selectActionFunction = function(fileUrl){

		

		document.getElementById( 'image' ).value = fileUrl ;

		//document.getElementById( 'img' ).src = fileUrl;

		

	}

	finder.popup() ;



	

}

</script>



<form  method="post" name="frmAddArticle">

<table style="width:100%" border="0" align="center" >

  <tr align="center">

    <td colspan="2" style="background:#008000;color:white; height:30px;"><h2>Tạo bài viết mới</h2></td>

  </tr>

  <tr>

    <td ><strong>Chuyên mục</strong>:</td>

    <td><?php echo $slcSection;?></td>

  </tr>
  <tr>

    <td ><strong>Danh mục menu</strong>:</td>

    <td><?php echo $slcmenu;?></td>

  </tr>

  <tr>

    <td width="30%" align="left"><strong>Xuất bản:</strong></td>

    <td>

    	<input  type="radio" name="published" value="1" checked="checked"/><label>Có</label>

        <input  type="radio" name="published" value="0"/><label>Không</label>

    </td>

  </tr>
     <tr>
     <td width="30%" align="left"><strong>Tin hót</strong></td>

    <td>

    	

    	<input  type="radio" name="featured" value="1" <?php echo ($article->featured==1)?"checked='checked'":""?>/><label>Có</label>

        <input  type="radio" name="featured" value="0" <?php echo ($article->featured==0)?"checked='checked'":""?>/><label>Không</label>

    </td>

  </tr>
  <tr>
     <td width="30%" align="left"><strong>Tin mới nhất</strong></td>

    <td>

    	

    	<input  type="radio" name="newshot" value="1" <?php echo ($article->newshot==1)?"checked='checked'":""?>/><label>Có</label>

        <input  type="radio" name="newshot" value="0" <?php echo ($article->newshot==0)?"checked='checked'":""?>/><label>Không</label>

    </td>

  </tr>

  <tr>

  		<td><strong>Hình ảnh</strong></td>

  		<td>

  			<input type="text" id="image" name="image" size="60"></input>

  			<input type="button" value="Chọn hình ảnh" onclick="BrowseServer();"/>

  		</td>

  </tr>
  


  <tr>

  	<td><strong>Từ khóa cho bài viết</strong></td>

  	<td><input type="text" name="tag" size="60"/></td>

  </tr>

  <tr>

  	<th colspan="2"  style="background:#e7e7e7; height:25px;">Nội dung Tiếng Việt</th>

  </tr>

 

  <tr>

    <td width="30%"><strong>Tiêu đề</strong></td>

    <td><input size="60" type="text" name="vi_title"/></td>

  </tr>



  <tr>

    <td width="30%"><strong>Tóm tắt</strong></td>

    <td><textarea name="vi_summary" style="width:400px; height:100px;"></textarea></td>

  </tr>

  

 

  <tr>

    <td> <strong>Nội dung</strong></td>

  </tr>

    

    <tr>

    	<td colspan="2">

        <?php

			// Automatically calculates the editor base path based on the _samples directory.

			// This is usefull only for these samples. A real application should use something like this:

			// $oFCKeditor->BasePath = '/fckeditor/' ;	// '/fckeditor/' is the index value.



			$sBasePath = ROOT_PATH.'fckeditor/' ;

			

			$oFCKeditor = new FCKeditor('vi_content') ;

			$oFCKeditor->BasePath	= $sBasePath ;

			$oFCKeditor->Value		= '';

			$oFCKeditor->Width		= 700;

			$oFCKeditor->Height		= 400;

			$oFCKeditor->Create() ;

		?>

        </td>

    </tr>

   <tr>

  	<th colspan="2"  style="background:#e7e7e7; height:25px;">Nội dung Tiếng Anh</th>

  </tr>

  <tr>

    <td width="30%"><strong>Tiêu đề</strong></td>

    <td><input size="60" type="text" name="en_title"/></td>

  </tr>



  <tr>

    <td width="30%"><strong>Tóm tắt</strong></td>

    <td><textarea name="en_summary" style="width:400px; height:100px;"></textarea></td>

  </tr>

  

 

  <tr>

    <td> <strong>Nội dung</strong></td>

  </tr>

    

    <tr>

    	<td colspan="2">

        <?php

			// Automatically calculates the editor base path based on the _samples directory.

			// This is usefull only for these samples. A real application should use something like this:

			// $oFCKeditor->BasePath = '/fckeditor/' ;	// '/fckeditor/' is the index value.



			$sBasePath = ROOT_PATH.'fckeditor/' ;

			

			$oFCKeditor = new FCKeditor('en_content') ;

			$oFCKeditor->BasePath	= $sBasePath ;

			$oFCKeditor->Value		= '';

			$oFCKeditor->Width		= 700;

			$oFCKeditor->Height		= 400;

			$oFCKeditor->Create() ;

		?>

        </td>

    </tr>

  <tr align="">

    <td>

      <strong>Thứ tự:      </strong></td>

    <td>
    	<input type="text" name="art_order" />
    	<span style="color: #a3a3a3; font-style: italic; margin-left: 10px;"> Số thự tự nhỏ sẽ hiện thị trước </span>

    </td>

    </tr>

  <tr align="center">

    <td colspan="2">

    	<input  type="button" name="btnSave" value="Thêm mới" onclick="addArticle();"/>

        <input  type="reset" name="btnReset" value="Làm lại" />

        </td>

    </tr>

</table>

</form>



<?php }?>